import os
import time
import calendar
import Tools
import re
import Db
import MySQLdb
import pymysql
import socket


def eachI(i):
    while i:
        if i < 10:
            adbScr('adb devices')
        else:
            break
        i = i + 1


def forTest(Data):
    for data in Data:
        print(data)


# 冒泡
def forNest(Data):
    n = len(Data)
    for i in range(n):
        for j in range(0, n - i - 1):
            if Data[j] > Data[j + 1]:
                Data[j], Data[j + 1] = Data[j + 1], Data[j]


def adbScr(shellStr):
    os.system(shellStr)


# 空元组
def createTup(item):
    if item != '':
        return (item)
    else:
        return ()


# socket
def getSocket():
    return socket.socket()


# 获取时间
def getTime(timeStr):
    return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timeStr))


if __name__ == '__main__':
    s = getSocket()
    host = socket.gethostname()
    s.bind((host, 12345))
    s.listen(5)
    while True:
        c, addr = s.accept()

        print('连接地址：', addr)
        str = 'abcdef'
        c.send(str.encode())
        c.close()  # 关闭连接

    # db = connect = MySQLdb.connect("localhost", "root", "root", "test", charset='utf8')
    # db = pymysql.connect(host="127.0.0.1", user="root", password="root", db="test", autocommit=True)
    # print(pymysql.cursors.DictCursor)
    # cursor = db.cursor(pymysql.cursors.DictCursor)
    # cursor.execute("select * from users")
    # Data = cursor.fetchall()
    # print(Data)
    # desc = cursor.description
    # arr = []
    # for d in desc:
    #     arr.append(d[0])
    #
    # j = 0
    # arrLen = len(arr)
    # for vals in Data:
    #     print(vals['id'], vals['username'])

    # for data in Data:
    #     for item in data:
    #         if j == arrLen:
    #             break
    #         else:
    #             print(arr[j] + ':' + str(item))
    #             j = j + 1

    # db.close()
    # print("Content-type:text/html")
    # print()  # 空行，告诉服务器结束头部
    # print('<html>')
    # print('<head>')
    # print('<meta charset="utf-8">')
    # print('<title>Hello World - 我的第一个 CGI 程序！</title>')
    # print('</head>')
    # print('<body>')
    # print('<h2>Hello World! 我是来自菜鸟教程的第一CGI程序</h2>')
    # print('</body>')
    # print('</html>')
    # str = input('请输入文件名称:')
    # files = open(str, 'w')
    # files.write('def getTime(timeStr): \n return 1')
    # files.close()

    # print(oct(1), hex(2), ord('1'))
    # eval('print((1)')
    # str1 = 'Hello World'
    # print(str1[1:])
    # print(str1[:6])
    # # 创建空元组
    # print(createTup(1))
    # # 字典
    # distory = {'Age': 19, 'Name': 'Jenson'}
    # print(distory)
    # print(distory['Age'])
    # print(distory['Name'])
    # print(distory.keys())
    # print(distory.values())
    #
    # newTime = time.time()
    # print(getTime(newTime))
    # print(calendar.month(2020, 2))
    # print('-----------------------')
    # print(calendar.calendar(2019, w=2, l=1, c=6))
    # print(Tools.Tools.abcd('fafas'))
    # print(re.match('www','www.baidu.com').span())
    # print(re.search('www','www.baidu.com').span)
